<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018\6\15 0015
 * Time: 15:30
 * 直播页面
 */
//todo 检测时间是否过去， 30分钟有效时间
$timeout = 1;
if( !empty($_GET['t']) ){
    $time = $_GET['t'];
    $time = intval( $time / 1000 );
    $now = time();
    $cha = $now - $time;
    if( $cha >= 0 && $cha < 1800 ){
        $timeout = 0;
    }
}

if( $timeout ){

    echo '链接已失效';
    exit;
}
$titles = [
        'gudingyi'  => '固定翼直播',
        'duoxuanyi' => '多旋翼直播',
        'hwsp'      => '红外视频直播',
        'soujiu'    => '搜救中心直播'
];
//todo 获取到参数 type : 'gudingyi' ,'duoxuanyi', 'hwsp', 'soujiu'
if( !empty($_GET['type']) ){
    $type = $_GET['type'];
}else{
    $type = 'gudingyi';
}
$title = !empty( $titles[$type] ) ? $titles[$type] : '视频直播';
//todo 根据 type 从redis 中获取到 ‘上直播网站’的直播参数，
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
$list = $redis->lrange($type, 0, -1);

$code = !empty($list) ? $list[0] : '';

if( empty( $code ) ){

    echo '直播不存在';
    exit();
}
//todo 根据 ‘上直播网站’的直播参数， 在静态代码中组装播放器
?>

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title><?php echo $title;?></title>

</head>

<body>

<iframe
    src="http://shangzhibo.tv/watch/<?php echo $code;?>?player"
    style="max-width: 1024px; width:100%; height: 576px; overflow:hidden;"
    scrolling="no" allowFullScreen>
</iframe>

</body>

</html>
